package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageBean;
import com.sky.service.SetmealService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@AllArgsConstructor
public class SetmealServiceImpl implements SetmealService {

    private final SetmealMapper setmealMapper;

    /**
     * 修改套餐
     *
     * @param setmealDTO 条件
     */

    @Override
    public void updateSetmeal(SetmealDTO setmealDTO) {
        setmealMapper.updateSetmeal(setmealDTO);
    }

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO 条件
     * @return PageBean
     */
    @Override
    public PageBean PageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
        Page page = setmealMapper.PageQuery(setmealPageQueryDTO);
        return new PageBean(page.getTotal(), page.getResult());
    }

    /**
     * 修改套餐状态
     *
     * @param status 状态
     * @param id     当前主键
     */

    @Override
    public void updateStatus(Integer status, Integer id) {
        setmealMapper.updateStatus(status, id);
    }

    /**
     * 批量删除套餐
     *
     * @param ids 套餐主键
     */
    @Override
    public void deleteByIds(List<Integer> ids) {
        setmealMapper.deleteByIds(ids);
    }

    /**
     * 新增套餐
     *
     * @param setmealDTO 条件
     */

    @Override
    public void addSetmeal(SetmealDTO setmealDTO) {
        setmealMapper.addSetmeal(setmealDTO);
    }

    /**
     * 根据id查询
     *
     * @param id 主键
     * @return Setmeal
     */
    @Override
    public Setmeal selectById(Integer id) {
        Setmeal setmeal = setmealMapper.selectById(id);
        return setmeal;
    }
}
